package cn.javass.dp.factorymethod.mydemo1;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public abstract class AbstractConnection {

protected  abstract Connection getConnection();

protected abstract void closeConn(Connection c);

/**
 * 关系型数据库 释放连接
 *
 * @param conn 连接
 * @param st   查询
 * @param rs   结果集
 */
protected static void release(Connection conn, Statement st, ResultSet rs) {
        try {
        if (null != conn) {
        conn.close();
        }

        } catch (SQLException e) {
        e.printStackTrace();
        } finally {
        conn = null;
        }

        try {
        if (null != st) {
        st.close();
        }
        } catch (SQLException e) {
        e.printStackTrace();
        } finally {
        st = null;
        }

        try {
        if (null != rs) {
        rs.close();
        }
        } catch (SQLException e) {
        e.printStackTrace();
        } finally {
        rs = null;
        }
        }
}
